package com.shuda.business.crm.controller;

import com.shuda.business.crm.entity.CustomerStatusHistoryEntity;
import com.shuda.business.crm.service.CustomerStatusHistoryService;
import com.shuda.common.core.domain.PageDTO;
import com.shuda.common.core.domain.PageResult;
import com.shuda.common.core.domain.R;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * 客户状态历史记录控制器
 */
@RestController
@RequestMapping("/api/crm/customers/status-history")
@Tag(name = "客户状态历史记录", description = "客户状态历史记录相关接口")
@RequiredArgsConstructor
public class CustomerStatusHistoryController {

    private final CustomerStatusHistoryService customerStatusHistoryService;

    /**
     * 获取客户状态历史记录分页列表
     */
    @GetMapping("/page")
    @Operation(summary = "获取客户状态历史记录分页列表", description = "根据客户ID获取状态历史记录分页列表")
    public R<PageResult<CustomerStatusHistoryEntity>> getCustomerStatusHistoryPage(
            @Parameter(description = "分页参数") PageDTO pageDTO,
            @Parameter(description = "客户ID") @RequestParam Long customerId) {
        return R.ok(customerStatusHistoryService.getCustomerStatusHistoryPage(pageDTO, customerId));
    }

    /**
     * 创建客户状态历史记录
     */
    @PostMapping
    @Operation(summary = "创建客户状态历史记录", description = "创建客户状态历史记录")
    public R<CustomerStatusHistoryEntity> createCustomerStatusHistory(@RequestBody CustomerStatusHistoryEntity historyEntity) {
        return R.ok(customerStatusHistoryService.createCustomerStatusHistory(historyEntity));
    }

    /**
     * 根据客户ID获取状态历史记录
     */
    @GetMapping("/{customerId}")
    @Operation(summary = "根据客户ID获取状态历史记录", description = "根据客户ID获取状态历史记录")
    public R<PageResult<CustomerStatusHistoryEntity>> getStatusHistoryByCustomerId(
            @Parameter(description = "分页参数") PageDTO pageDTO,
            @PathVariable Long customerId) {
        return R.ok(customerStatusHistoryService.getStatusHistoryByCustomerId(pageDTO, customerId));
    }
}